package com.liwang.lanouhn.nvshengo.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.liwang.lanouhn.nvshengo.Info.Info;
import com.liwang.lanouhn.nvshengo.Info.LoveInfo;
import com.liwang.lanouhn.nvshengo.R;
import com.liwang.lanouhn.nvshengo.activities.LunBoDetailsActivity;
import com.liwang.lanouhn.nvshengo.view.RecyclerImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by lanouhn on 2016/10/20.
 */
public class LoveAdapter extends RecyclerView.Adapter<LoveAdapter.LoveViewHolder> {
    private Context context;
    private List<LoveInfo.DataBean.WallBean.ListBean> listBean;

    public LoveAdapter(Context context, List<LoveInfo.DataBean.WallBean.ListBean> listBean) {
        this.context = context;
        this.listBean = listBean;
    }

    @Override
    public LoveViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_clothesxrecycler, null);
        LoveViewHolder holder = new LoveViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(LoveViewHolder holder, final int position) {
        Picasso.with(context).load(listBean.get(position).getImg()).fit().config(Bitmap.Config.RGB_565).into(holder.iv_picture);
        if (listBean.get(position).getLeftbottom_taglist().size() == 1) {
            Picasso.with(context).load(listBean.get(position).getLeftbottom_taglist().get(0)).fit().config(Bitmap.Config.RGB_565).into(holder.iv_leftbottom);
        }
        if (listBean.get(position).getLeftbottom_taglist().size() == 2) {
            Picasso.with(context).load(listBean.get(position).getLeftbottom_taglist().get(0)).fit().config(Bitmap.Config.RGB_565).into(holder.iv_leftbottom);
            Picasso.with(context).load(listBean.get(position).getLeftbottom_taglist().get(1)).fit().config(Bitmap.Config.RGB_565).into(holder.iv_leftbottom2);
        }
        if (listBean.get(position).getLeftbottom_taglist().size() == 3) {
            Picasso.with(context).load(listBean.get(position).getLeftbottom_taglist().get(0)).fit().config(Bitmap.Config.RGB_565).into(holder.iv_leftbottom);
            Picasso.with(context).load(listBean.get(position).getLeftbottom_taglist().get(1)).fit().config(Bitmap.Config.RGB_565).into(holder.iv_leftbottom2);
            Picasso.with(context).load(listBean.get(position).getLeftbottom_taglist().get(2)).fit().config(Bitmap.Config.RGB_565).into(holder.iv_leftbottom3);
        }
        holder.tv_love_title.setText(listBean.get(position).getTitle());
        holder.tv_love_price.setText(listBean.get(position).getPrice());
        holder.tv_love_favourite.setText(listBean.get(position).getCfav());
        holder.iv_similar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Info infos = new Info();
                infos.setTitle("相似商品");
                infos.setUrl(listBean.get(position).getSimilarityUrl());
                Intent intent = new Intent(context, LunBoDetailsActivity.class);
                intent.putExtra("info", infos);
                context.startActivity(intent);
            }
        });
        holder.ll_love.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Info info1 = new Info();
                info1.setTitle(listBean.get(position).getTitle());
                info1.setUrl(listBean.get(position).getLink());
                Intent intent1 = new Intent(context, LunBoDetailsActivity.class);
                intent1.putExtra("info", info1);
                context.startActivity(intent1);
            }
        });


    }

    @Override
    public int getItemCount() {
        return listBean.size();
    }
    public class LoveViewHolder extends RecyclerView.ViewHolder {
        public RecyclerImageView iv_picture;
        public ImageView iv_similar;
        public TextView tv_love_title;
        public ImageView iv_leftbottom, iv_leftbottom2, iv_leftbottom3;
        public TextView tv_love_price;
        public ImageView iv_love_favourite;
        public TextView tv_love_favourite;
        private LinearLayout ll_love;

        public LoveViewHolder(View itemView) {
            super(itemView);
            iv_picture = (RecyclerImageView) itemView.findViewById(R.id.iv_picture);
            iv_similar = (ImageView) itemView.findViewById(R.id.iv_similar);
            ll_love= (LinearLayout) itemView.findViewById(R.id.ll_love);
            tv_love_title = (TextView) itemView.findViewById(R.id.tv_love_title);
            iv_leftbottom = (ImageView) itemView.findViewById(R.id.iv_leftbottom);
            iv_leftbottom2 = (ImageView) itemView.findViewById(R.id.iv_leftbottom);
            iv_leftbottom3 = (ImageView) itemView.findViewById(R.id.iv_leftbottom);
            tv_love_price = (TextView) itemView.findViewById(R.id.tv_love_price);
            iv_love_favourite = (ImageView) itemView.findViewById(R.id.iv_love_favourite);
            tv_love_favourite = (TextView) itemView.findViewById(R.id.tv_love_favourite);
        }
    }


}
